﻿using IntelligentAgriculture.Contracts.Dto.Input;
using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.PurchaseFormModelCommand;
using IntelligentAgriculture.WebAPI.Application.Command.SheepfilemodelCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace IntelligentAgriculture.WebAPI.Controllers
{
	/// <summary>
	/// 羊只采购
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class PurchaseFormModelController : ControllerBase
	{
		/// <summary>
		/// 构造函数
		/// </summary>
		private readonly IMediator _mediator;
		private readonly ILogger<PurchaseFormModelController> _logger;
		/// <summary>
		/// 构造方法
		/// </summary>
		/// <param name="mediator"></param>
		public PurchaseFormModelController(IMediator mediator, ILogger<PurchaseFormModelController> logger)
		{
			_mediator = mediator;
			_logger = logger;
		}
		/// <summary>
		/// 羊只采购列表
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Results<PageOutput<PurchaseformmodelOutOut>>> GetPurchaseForms(PurchaseformmodelInPut input)
		{
			try
			{
				var command=new GetPurchaseFormsCommand(input);
				return await _mediator.Send(command);
			}
			catch (Exception ex)
			{
				_logger.LogError("羊只采购列表异常"+ex.Message);
				throw;
			}
		}
		/// <summary>
		/// 养只采购添加
		/// </summary>
		/// <param name="inputs"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Results<int>> AddPurchaseForms(List<PurchaseFormsAddInput> inputs)
		{
			try
			{
				var command = new AddPurchaseFormsCommand(inputs);
				return await _mediator.Send(command);
			}
			catch (Exception ex)
			{
				_logger.LogError("羊只采购添加异常"+ex.Message);
				throw;
			}
		}
		/// <summary>
		/// 获取摘要
		/// </summary>
		/// <param name="command"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<Results<List<object>>> GetSummaryEnum()
		{
			try
			{
				var command = new GetSummaryEnumCommand();
				return await _mediator.Send(command);
			}
			catch (Exception ex)
			{
				_logger.LogError("获取摘要异常" + ex.Message);
				throw;
			}
		}
		/// <summary>
		/// 养只档案删除
		/// </summary>
		/// <returns></returns>
		[HttpPost]
		public async Task<Results<int>> DelPurchaseForms(params int[]  ids)
		{
			try
			{
				var command = new DelPurchaseFormsCommand(ids);
				return await _mediator.Send(command);
			}
			catch (Exception ex)
			{
				_logger.LogError("养只档案删除异常" + ex.Message);
				throw;
			}
		}
		/// <summary>
		/// 养只采购反填
		/// </summary>
		/// <returns></returns>
		[HttpGet]
		public async Task<Results<Purchaseformmodel>> Purchaseformmodel(int purchaseFormId)
		{
			try
			{
				var command=new DetailPurchaseformmodelCommand(purchaseFormId);
				return await _mediator.Send(command);
			}
			catch (Exception ex)
			{
				_logger.LogError("养只采购反填异常" + ex.Message);
				throw;
			}
		}
		/// <summary>
		/// 羊只采购修改
		/// </summary>
		/// <param name="command"></param>
		/// <returns></returns>
		[HttpPut]
		public async Task<Results<int>> UpdatePurchaseformmodel(UpdatePurchaseformmodelCommand command)
		{
			try
			{
				return await _mediator.Send(command);
			}
			catch (Exception ex)
			{

				throw;
			}
		}
	}
}
